package com.crudpro.javacrud.config;

import com.crudpro.javacrud.auth.JwtInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@RequiredArgsConstructor
public class WebConfig implements WebMvcConfigurer {

    private final JwtInterceptor jwtInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor)
                // Protect all API endpoints
                .addPathPatterns("/tables/**") // Protect the tables API
                .addPathPatterns("/users/**")  // Protect the users API
                .addPathPatterns("/auth-test/**") // Protect the auth test endpoint
                // Exclude authentication endpoints
                .excludePathPatterns("/auth/**")
                // Exclude public endpoints if any
                .excludePathPatterns("/");
    }
} 